<?php


namespace Usap\Service\Operation;
class companies
{

    /**添加单位信息*/
    public function add_companies_info($data)
    {
        $model = D("Usap/Common/Companies");
        return $model->add($data);
    }


    public function update_companies_info($id, $data)
    {
        $model = D("Usap/Common/Companies");
        return $model->where(['company_id' => $id])->save($data);
    }

    /*获取单位列表*/
    public function get_companies_list($where)
    {
        $model = D("Usap/Common/Companies");
        $count = $model->where($where)->count();
        $list = [];
        if ($count > 0) {
            $list = $model->where($where)->select();
        }
        $result = [
            'count' => $count ? $count : 0,
            'list' => $list
        ];
        return $result;
    }

    public function getCompaniesInfoById($id)
    {
        return D("Usap/Common/Companies")->where(['company_id' => $id])->find();
    }

    public function getCompaniesByCondition($condition)
    {
        return D("Usap/Common/Companies")->where($condition)->find();
    }

    public function get_companies_config()
    {
        return D("Usap/Common/Companies")->getField('company_id,name');
    }


    public function deleteCompanies($id)
    {
        $model = D("Usap/Common/Companies");
        return $model->where(['company_id' => $id])->delete();
    }

    public function get_companies_id()
    {
        return D("Usap/Common/Companies")->order('company_id desc')->getField('company_id');

    }
}